<?php

function member_favorite_restaurant_offer_page(){
    
        global $user;
        $header = array(
        array('data' => 'Ajánlat időpontja', 'field' => 'startdate'),            
	array('data' => 'Ajánlat', 'field' => 'offer', 'sort' => 'asc'),
	array('data' => 'Étterem neve', 'field' => 'name'),
	array('data' => 'Ár(Ft)', 'field' => 'price'),

	);
        
        $query = db_select('ep_favourite_restaurant', 'fr');
        $query->join('ep_offers', 'o', 'fr.rid = o.rid');
        $query->join('ep_restaurants', 'r', 'fr.rid = r.rid');
        $query->fields('fr',array('rid','uid'))
                ->fields('o',array('offer','startdate','oid','price'))
                ->fields('r',array('name','rid'))
                ->extend('TableSort')
                    ->orderByHeader($header);
        $query -> condition('fr.uid',$user->uid,'=');
        
        $results = $query
			->execute();
        $rows = array();	
        foreach ($results as $favourite) {
	$rows[] = array(
				'data' => array(
                                          $favourite->startdate,
					  '<a href="'.url('member/offer_info/'.$favourite->oid).'">'.$favourite->offer.'</a>'.member_add_offer_to_favourite_control($favourite->oid),
					  '<a href="'.url('member/restaurants_offers/'.$favourite->rid).'">'.$favourite->name.member_add_restaurant_to_favourite_control($favourite->rid),
                                          $favourite->price,

				)
        );
        }
        $html = theme('table', 
			array(
				'header' => $header,
				'rows'=>$rows,
				'sticky' => TRUE,		
				'empty' => t('Nincs elem ebben a listában...'),
			)
		);

        return $html;
} 